package bTree.LeetCode;

import javax.swing.text.Keymap;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class 最长连续序列 {
    public int longestConsecutive(int[] nums) {
        int maxLen=0;
        Map<Integer,Integer>map=new HashMap<>();
        for (int num : nums) {
            if (map.containsKey(num-1)){
                maxLen=Math.max(maxLen,map.get(num-1)+1);
                map.put(num,map.get(num-1)+1);
            } else if (map.containsKey(num-1)) {
                
            } else {
                map.put(num,1);
            }
        }
        return maxLen;
    }
}